import {getGoodsData} from "../modules/api.js";

const data = await getGoodsData();

const localData = localStorage.getItem("goods") ? JSON.parse(localStorage.getItem("goods")) : [];

let tBodyStr = "";
data.forEach(val1=>{
    localData.forEach(val2=>{
        if(val1.id === val2.id){
            tBodyStr += 
            `<tr myid="${val2.id}">
                <td><input type="checkbox" ${val2.check ? 'checked' : ''} class="check"></td>
                <td><img src="${val1.img}"></td>
                <td>${val1.name}</td>
                <td><input class="num" type="number" value="${val2.num}"></td>
                <td>${val2.price}</td>
                <td class="count">${val2.price * val2.num}</td>
                <td class="del">删除</td>
            </tr>`
        }
    })
})



let str = 
`<table border="1" width="700" align="center">
    <thead>
        <tr>
            <th>选中</th>
            <th>图片</th>
            <th>名字</th>
            <th>数量</th>
            <th>单价</th>
            <th>小计</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        ${tBodyStr}
    </tbody>
    <tfoot>
        <tr>
            <td colspan="2"><input class="allCheck" type="checkbox">全选</td>
            <td align="right">总数量</td>
            <td class="sum">0</td>
            <td>总价</td>
            <td class="sumPrice">0</td>
            <td class="delCheck">删除选中</td>
        </tr>
    </tfoot>
    </table>`;
    
export default str;